<% from trackerclientpylons.model.result import Mp3 %>

${h.javascript_tag(h.update_element_function("count",action='empty'))}
${h.javascript_tag(h.update_element_function("cats",action='empty'))}
${h.javascript_tag(h.update_element_function("arrows",action='empty'))}

% if session['rs'].hasPrev():
	${h.javascript_tag(h.update_element_function("arrows",position='bottom', content=h.submit_to_remote('prev', 'Previous', url=h.url_for(action="prev"), loading=h.visual_effect('Pulsate', "loading"), update='results')))}
% else:
	${h.javascript_tag(h.update_element_function("arrows",position='bottom', content="<input type='button' value='Previous' disabled='true'/>"))}
% endif

% if session['rs'].hasNext():
	${h.javascript_tag(h.update_element_function("arrows",position='bottom', content=h.submit_to_remote('next', 'Next', url=h.url_for(action="next"), loading=h.visual_effect('Pulsate', "loading"), update='results')))} 
% else:
	${h.javascript_tag(h.update_element_function("arrows",position='bottom', content="<input type='button' value='Next' disabled='true'/>"))}
% endif

<table width="100%" border="0">

<% i = 0 %>
<% j = 0 %>

${h.javascript_tag(h.update_element_function("cats",position='bottom', content="<ul>"))}

${h.javascript_tag(h.update_element_function("cats",position='bottom', content="<li>%s</li>" % h.link_to_remote("All", dict(update="results", url=h.url_for(action='find', query=request.params['query'])))))}

% for cat, items in session['rs'].results().iteritems():

		% if j % 2:
			${h.javascript_tag(h.update_element_function("cats",position='bottom', content="<li>%s</li>" % h.link_to_remote(cat, dict(update="results", loading=h.visual_effect('Pulsate', "loading"), url=h.url_for(action='find', filter=cat, query=request.params['query'])))))}
		% else:
			${h.javascript_tag(h.update_element_function("cats",position='bottom', content="<li>%s</li>" % h.link_to_remote(cat, dict(update="results", loading=h.visual_effect('Pulsate', "loading"), url=h.url_for(action='find', filter=cat, query=request.params['query'])))))}
		% endif
		
		<% j = j + 1 %>

		% for item in items:
		
			% if i % 2:
				<tr>
			% else:
			  	<tr bgcolor="#d6e1fb">
			% endif
			
			<td>
			<input type="checkbox" name="choices" value="choice${i}"/>
			
			<img width="32" height="32" src="${h.url_for(action="icon", uri=item.url)}"/>
			
			<b> ${h.link_to_remote(item.name, dict(update="detail" + str(i), loading=h.visual_effect('Pulsate', "loading"), url=h.url_for(action='detail', url=item.url)))} </b><br>
			
			${item.url}
						
			% if isinstance(item, Mp3):
				<br><font size="-1">Title: ${ item.title }, Artist: ${item.artist}</font>
			% endif
			
			<br><font size="-1">${ session['rs'].text_snippet(item.url) }</font>
			
			<div id="detail${i}"/>
			
			</td>
			</tr>
			
			<% i = i + 1 %>
		
		% endfor
		
% endfor
</table>

${h.javascript_tag(h.update_element_function("cats",position='bottom', content="</ul>"))}
${h.javascript_tag(h.update_element_function("count",position='bottom', content="<p>Search Results: Showing %s to %s of %s matches</p>" % (session['rs'].query.offset + 1, session['rs'].query.offset + i,session['rs'].totalResults)    ))}
    